package com.example.demo.day0302;
/**
 * 对象的序列化与反序列化使用的类要严格一致，包名，类名，类j结构等等所有都要一致
 */
import java.io.FileInputStream;
import java.io.ObjectInputStream;


public class DemoDeserialize {
    public static void main(String[] args) {
        try {
            DemoDeserialize.testDemoDeserialize();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    public static void testDemoDeserialize() throws Exception {
        ObjectInputStream in = new ObjectInputStream(new FileInputStream("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt8.txt"));
        //创建对象输入流对象，从指定的文件中把对象序列化后的流读取出来
        Object obj = in.readObject();

        Man m = (Man) obj;//不同类型的数据需要强行转换

        System.out.println(m.name);
        System.out.println(m.age);

        in.close();//关闭流


    }
}
